const Crypto = require("crypto");

function _(e) {
    e = Crypto.createHash("md5").update(e.toString()).digest("hex")
    return e;
}

function S(e, client, product, t) {
    return _(`client=${client}&mysticTime=${e}&product=${product}&key=${t}`)
}

function GetSign(date, client, product, key) {
    return S(date, client, product, key)
}

function T(e) {
    return Crypto.createHash("md5").update(e).digest()
}

function DecodeResult(data, key, iv) {
    const a = Buffer.alloc(16, T(key));
    const n = Buffer.alloc(16, T(iv));
    const r = Crypto.createDecipheriv("aes-128-cbc", a, n);
    let l = r.update(data, "base64", "utf-8")
    l += r.final("utf-8")
    return l;
}


